/**
 * 
 */
package com.alkandros.myloke.managers;

import java.io.IOException;
import java.util.ArrayList;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import com.alkandros.myloke.models.FaithModel;
import com.alkandros.myloke.utils.ObjectSerializer;

/**
 * @author Jiju Induchoodan
 *
 */
public class AppPreferenceManager {
	
	public static void saveUserNumber(String number,Context context) 
	{
		SharedPreferences preferences;
		preferences = context.getSharedPreferences("MyLoke",Context.MODE_PRIVATE);
		preferences.edit().putString("user_number", number).commit();
	}
	
	public static String getUserNumber(Context context) 
	{
		SharedPreferences preferences;
		preferences = context.getSharedPreferences("MyLoke",Context.MODE_PRIVATE);
		String  userId = preferences.getString("user_number", "");
		return userId;
	}
	
	public static void saveUserName(String number,Context context) 
	{
		SharedPreferences preferences;
		preferences = context.getSharedPreferences("MyLoke",Context.MODE_PRIVATE);
		preferences.edit().putString("user_name", number).commit();
	}
	
	public static String getUserName(Context context) 
	{
		SharedPreferences preferences;
		preferences = context.getSharedPreferences("MyLoke",Context.MODE_PRIVATE);
		String  userId = preferences.getString("user_name", "");
		return userId;
	}
	
	public static void saveFaith(String faith,Context context) 
	{
		SharedPreferences preferences;
		preferences = context.getSharedPreferences("MyLoke",Context.MODE_PRIVATE);
		preferences.edit().putString("user_faith", faith).commit();
	}
	
	public static String getFaith(Context context) 
	{
		SharedPreferences preferences;
		preferences = context.getSharedPreferences("MyLoke",Context.MODE_PRIVATE);
		String  faith = preferences.getString("user_faith", "");
		return faith;
	}
	
	public static void saveMiles(String number,Context context) 
	{
		SharedPreferences preferences;
		preferences = context.getSharedPreferences("MyLoke",Context.MODE_PRIVATE);
		preferences.edit().putString("user_miles", number).commit();
	}
	
	public static String getMiles(Context context) 
	{
		SharedPreferences preferences;
		preferences = context.getSharedPreferences("MyLoke",Context.MODE_PRIVATE);
		String  miles = preferences.getString("user_miles", "5");
		return miles;
	}
	
	public static void saveFaithList(Context ctx,ArrayList<FaithModel> list)
	{
			SharedPreferences prefs = ctx.getSharedPreferences("MyLoke", Context.MODE_PRIVATE);
	        Editor editor = prefs.edit();
	        editor.putString("faithlist", ObjectSerializer.serialize(list));
	        editor.commit();
	}
	
	public static ArrayList<FaithModel> getFaithList(Context ctx)
	{
		ArrayList<FaithModel> listItems = null;
		 SharedPreferences prefs = ctx.getSharedPreferences("MyLoke", Context.MODE_PRIVATE);

	     try {
	    	 listItems = (ArrayList<FaithModel>) ObjectSerializer.deserialize(prefs.getString("faithlist",ObjectSerializer.serialize(new ArrayList<FaithModel>())));
	     } 
	     catch (IOException e)
	     {
	         e.printStackTrace();
	     }
		return listItems;
	}

}
